﻿<UserControl x:Class="Collab.Collab_Modules_VSPackage.CollaborationControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0"
             xmlns:local="clr-namespace:Collab.Collab_Modules_VSPackage"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Name="CollaborationControlToolWindow">
    <UserControl.Resources>
        <local:ColorTupleToBrushConverter x:Key="TupleConverter" />
        <Style TargetType="{x:Type ListBox}" x:Key="ContactListBoxStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <ItemsPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <ContextMenu x:Key="ListBoxItemContextMenu">
            <MenuItem x:Name="NavigateToUser" Header="Navigate to User" CommandParameter="{Binding Status.ActiveFile}" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                    AncestorType=ListBox}, Path=DataContext.NavigateToCommand}" />
        </ContextMenu>

        <Style TargetType="{x:Type ListBoxItem}" x:Key="ContactListBoxItem">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                    Color="AliceBlue"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" 
                    Color="Transparent"/>
            </Style.Resources>

            <Setter Property="ContextMenu" Value="{StaticResource ListBoxItemContextMenu}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="BorderThickness" Value="0,0,0,3" />
            <Setter Property="BorderBrush" Value="#ffacacac" />
        </Style>

        <Style TargetType="{x:Type TextBox}" x:Key="InvisibleTextBox">

            <Setter Property="BorderThickness" Value="0,0,0,0" />
            <Setter Property="Background" Value="#00000000" />
        </Style>

        <SolidColorBrush x:Key="UserIconBodyBrush" Color="#FF898989" />

        <DataTemplate x:Key="ContactListTemplate">
            <Border Padding="2,2,2,2" HorizontalAlignment="Stretch" Height="36">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="20" />
                        <RowDefinition Height="20" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Canvas Grid.Column="0" Grid.RowSpan="2" Grid.Row="0" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Untitled1" Width="32" Height="32" Clip="F1 M 0,0L 32,0L 32,32L 0,32L 0,0">
                        <Canvas x:Name="Layer_1" Width="32" Height="32" Canvas.Left="0" Canvas.Top="0">
                            <Path x:Name="Path" Width="28.0417" Height="16.5578" Canvas.Left="1.95833" Canvas.Top="13.5195" Stretch="Fill" Fill="{StaticResource UserIconBodyBrush}" Data="F1 M 1.95833,30C 1.95833,27.5694 1.95833,25.1389 2.63194,22.4583C 3.30556,19.7778 4.65278,16.8472 6.99306,15.2778C 9.33333,13.7083 12.6667,13.5 16,13.5208C 19.3333,13.5417 22.6667,13.7917 25,15.4028C 27.3333,17.0139 28.6667,19.9861 29.3333,22.6528C 30,25.3194 30,27.6806 30,30.0417C 2,30.125 2,30.0417 1.95833,30 Z "/>
                        </Canvas>
                        <Canvas x:Name="Layer_3" Width="32" Height="32" Canvas.Left="0" Canvas.Top="0">
                            <Path x:Name="Path_0" Width="8.5757" Height="7.42677" Canvas.Left="11.841" Canvas.Top="13.7122" Stretch="Fill" Fill="#FFFFFFFF" Data="F1 M 13.054,15.8133L 16.1288,21.139L 20.4167,13.7122L 11.841,13.7122"/>
                            <Path x:Name="Line" Width="2.24928" Height="3.89586" Canvas.Left="8.0493" Canvas.Top="6.70133" Stretch="Fill" Data="F1 M 8.0493,6.70133L 10.2986,10.5972"/>
                        </Canvas>
                        <Canvas x:Name="Layer_4" Width="32" Height="32" Canvas.Left="0" Canvas.Top="0">
                            <Path x:Name="Path_1" Width="4.22917" Height="7.33333" Canvas.Left="14" Canvas.Top="16" Stretch="Fill" Fill="{Binding Color, Converter={StaticResource TupleConverter }}" Data="F1 M 15,16.0208L 14,19.6458L 16.125,23.3333L 18.2292,19.6667L 17,16L 16.1667,16.0625L 15.5,16.0208L 15,16.0208 Z "/>
                        </Canvas>
                        <Canvas x:Name="Layer_2" Width="32" Height="32" Canvas.Left="0" Canvas.Top="0">
                            <Ellipse x:Name="Ellipse" Width="14" Height="14" Canvas.Left="9" Canvas.Top="2.04167" Stretch="Fill" Fill="{StaticResource UserIconBodyBrush}"/>
                        </Canvas>
                    </Canvas>
                    <TextBlock Padding="2,2,2,0" Grid.Column="1" Grid.Row="0" Text="{Binding Name}" FontSize="11"/>
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
                        <TextBlock Padding="2,0,2,1" Grid.Column="1" Grid.Row="1" Text="{Binding Status.ActiveFile}" FontSize="9"/>
                        <TextBlock Padding="2,0,2,1" Grid.Column="1" Grid.Row="1" Text="   " FontSize="9"/>
                        <TextBlock Padding="2,0,2,1" Grid.Column="1" Grid.Row="1" Text="{Binding Status.Selection.CaretLine}" FontSize="8"/>

                    </StackPanel>

                </Grid>
            </Border>
        </DataTemplate>


    </UserControl.Resources>
    <Grid Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid Margin="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Button Content="Host" Command="{Binding HostCommand}" IsEnabled="{Binding CanHost}" Margin="2"/>
            <Button Content="Join" Command="{Binding JoinCommand}" IsEnabled="{Binding CanJoin}" Margin="2" Grid.Column="1"/>
            <Button Margin="2" Command="{Binding LeaveCommand}" IsEnabled="{Binding CanLeave}" Content="Leave" Grid.Column="2"/>
        </Grid>
        <DockPanel Grid.Row="1">
            <Border Padding="10,0,0,10" BorderThickness="0,0,0,1" BorderBrush="#FF898989" DockPanel.Dock="Top">
                <StackPanel>
                    <TextBlock>You are connected to:</TextBlock>
                    <TextBox IsReadOnly="True" Text="{Binding IP}" Style="{StaticResource InvisibleTextBox}" TextWrapping="Wrap" />
                </StackPanel>
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFC7C7C7" Offset="0" />
                        <GradientStop Color="#FFE2E2E2" Offset="1" />
                    </LinearGradientBrush>
                </Border.Background>
            </Border>

            <Button DockPanel.Dock="Bottom" Opacity="0.2" HorizontalAlignment="Right" Margin="2" Command="{Binding PrintDebugCommand}" Content="PrintDebug" />


            <ListBox HorizontalAlignment="Stretch" Background="White" ItemsSource="{Binding Users}" ItemTemplate="{StaticResource ContactListTemplate}"
                 ItemContainerStyle="{StaticResource ContactListBoxItem}" Style="{StaticResource ContactListBoxStyle}" SelectedItem="{Binding Path=SelectedContact}">

            </ListBox>

        </DockPanel>
    </Grid>
</UserControl>
